package com.leadingsoft.pwxk;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

import com.leadingsoft.pwxk.service.DrainCountService;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableJpaRepositories
@EntityScan
@EnableSwagger2
@EnableCaching
@Configuration
@EnableScheduling
public class DataApiApplication {

	@Autowired
	private DrainCountService drainCountService;

	public static void main(String[] args) throws Exception {
		SpringApplication.run(DataApiApplication.class, args);
	}

	@Bean
	public RestTemplate RestTemplate() {
		return new RestTemplate();
	}

	@Bean
	public NamedParameterJdbcTemplate NamedParameterJdbcTemplate(@Autowired DataSource dataSource) {
		return new NamedParameterJdbcTemplate(dataSource);
	}

	// @PostConstruct
	void DrainCountCache() {
		try {
			drainCountService.airCountOne(null);
			drainCountService.waterCountOne(null);
		} catch (Exception e) {
		}

	}

}
